<?php
/**
 * @copyright 2011
 * @version $Id$
 * @access public
 * @author Oriotiori
 */


Class Default_Model_ModuleResource extends Zend_Db_Table_Abstract
{		
	protected $_name = 'moduleresources';
	
	
	/**
	 * Model_moduleType::ReadModuleTypeByResource()
	 * Lee los m�dulos para un recurso del sistema.
	 * @param mixed $moduleType: objeto con los datos del recurso.
	 * @return
	 */
	function ReadModuleByResource($resource)
	{		
		$this->_name = TABLE_PREFIX.'moduleresources';

		$TOModuleType = new Default_Model_TO_Resource();
		

		try{
                    $sql=$this
                        ->getAdapter()
                        ->select()
                        ->from(
                                array('mr' => $this->_name),
                                'mr.Id_module')
                        ->joinInner(
                                array('r' => TABLE_PREFIX.'resource'),
                                'r.Id=mr.Id_resource',
                                'r.Id')
                        ->where('r.Description=?', $resource['Description']);
                        
                   
                    $data = $this->getAdapter()->fetchAll($sql);
                    $rowCount = count($data);

                    if ($rowCount > 0){
                        
                        foreach($data as $dt){
                                $TOModuleType->setId($dt['Id_module']);
                                $TOModuleType->setIdResource($dt['Id']);
                                $TOModuleType->add();
                        }

                        $moduleType = $TOModuleType->getAllData();
                        return $moduleType;
                    }
                    else{}
			
		}catch(Exception $e)
		{
                    
                    $error=array($e->getFile(), 'Exception: '.$e->getMessage());
                    $ExceptionHandler= new Default_Model_ExceptionHandler();
                    $ExceptionHandler->saveErrors($error);
                }
	}
	
	
	
				
}


?>